package Project.Zoo;

import java.util.Scanner;

public class Test {

    public static void showName(Animal []animal){
        System.out.println("动物名字\t动物叫");
        for (int i = 0; i <animal.length ; i++) {
            System.out.print(animal[i].getName()+"\t");
            animal[i].shout();
        }
    }
    public static void showLegNum(Animal [] animal){
        System.out.println("动物名字\t\t腿的条数\t\t动物叫");
        for (int i = 0; i <animal.length ; i++) {
            if (animal[i] instanceof Cat) {
                System.out.print(animal[i].getName()+"\t\t"+animal[i].getLegNum()+"\t\t\t");
                animal[i].shout();
            }else if(animal[i] instanceof Duck){
                System.out.print(animal[i].getName()+"\t\t"+animal[i].getLegNum()+"\t\t\t");
                animal[i].shout();
            }else if(animal[i] instanceof Dolphin){
                System.out.print(animal[i].getName()+"\t\t"+animal[i].getLegNum()+"\t\t\t");
                animal[i].shout();
            }
        }
    }
    public static void modify(Animal[] animal)throws Exception{
        int num=0;
        Scanner in=new Scanner(System.in);
        do {
            System.out.print("是否要继续修改数据，按0进行修改操作，其他任意数字退出：");
             num=in.nextInt();
            if (num == 0) {
                System.out.println("请选择修改哪种动物的信息(1.猫2.鸭子3.海豚)");
                int choice=in.nextInt();
                switch (choice){
                    case 1:
                        System.out.println("请输入猫的名字：");
                        String name=in.next();
                        System.out.println("请输入猫腿的条数：");
                        int legNum=in.nextInt();
                        animal[0]=new Cat(name,legNum);
                        break;
                    case 2:
                        System.out.println("请输入鸭子的名字：");
                         name=in.next();
                        System.out.println("请输入鸭子腿的条数：");
                        legNum=in.nextInt();
                        animal[1]=new Duck(name,legNum);
                        break;
                    case 3:
                        System.out.println("请输入海豚的名字：");
                        name=in.next();
                        System.out.println("请输入海豚腿的条数：");
                        legNum=in.nextInt();
                        animal[2]=new Dolphin(name);
                        animal[2].setLegNum(legNum);
                        break;
                }
            }else{
                break;
            }

        }while (num!=0);
    }
    public static void main(String[] args) throws Exception {
        Animal animal[]=new Animal[3];
        animal[0]=new Cat("加菲猫",4);
        animal[1]=new Duck("唐老鸭",2);
        animal[2]=new Dolphin("海豚奇奇");
        showName(animal);
        System.out.println("----------------------------");
        showLegNum(animal);
        modify(animal);
    }
}
